/**
 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package fr.smile.liferay.portlet.news.model.impl;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.DateUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.service.ServiceContext;
import com.liferay.portal.util.PortalUtil;

import com.liferay.portlet.expando.model.ExpandoBridge;
import com.liferay.portlet.expando.util.ExpandoBridgeFactoryUtil;

import fr.smile.liferay.portlet.news.model.NewsFlag;
import fr.smile.liferay.portlet.news.model.NewsFlagModel;
import fr.smile.liferay.portlet.news.model.NewsFlagSoap;

import java.io.Serializable;

import java.lang.reflect.Proxy;

import java.sql.Types;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * The base model implementation for the NewsFlag service. Represents a row in the &quot;News_NewsFlag&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link fr.smile.liferay.portlet.news.model.NewsFlagModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link NewsFlagImpl}.
 * </p>
 *
 * <p>
 * Never modify or reference this class directly. All methods that expect a news flag model instance should use the {@link fr.smile.liferay.portlet.news.model.NewsFlag} interface instead.
 * </p>
 *
 * @author Brian Wing Shun Chan
 * @see NewsFlagImpl
 * @see fr.smile.liferay.portlet.news.model.NewsFlag
 * @see fr.smile.liferay.portlet.news.model.NewsFlagModel
 * @generated
 */
public class NewsFlagModelImpl extends BaseModelImpl<NewsFlag>
	implements NewsFlagModel {
	public static final String TABLE_NAME = "News_NewsFlag";
	public static final Object[][] TABLE_COLUMNS = {
			{ "flagId", new Integer(Types.BIGINT) },
			{ "userId", new Integer(Types.BIGINT) },
			{ "createDate", new Integer(Types.TIMESTAMP) },
			{ "entryId", new Integer(Types.BIGINT) },
			{ "value", new Integer(Types.INTEGER) }
		};
	public static final String TABLE_SQL_CREATE = "create table News_NewsFlag (flagId LONG not null primary key,userId LONG,createDate DATE null,entryId LONG,value INTEGER)";
	public static final String TABLE_SQL_DROP = "drop table News_NewsFlag";
	public static final String ORDER_BY_JPQL = " ORDER BY newsFlag.userId ASC, newsFlag.createDate ASC";
	public static final String ORDER_BY_SQL = " ORDER BY News_NewsFlag.userId ASC, News_NewsFlag.createDate ASC";
	public static final String DATA_SOURCE = "liferayDataSource";
	public static final String SESSION_FACTORY = "liferaySessionFactory";
	public static final String TX_MANAGER = "liferayTransactionManager";
	public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.entity.cache.enabled.fr.smile.liferay.portlet.news.model.NewsFlag"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.fr.smile.liferay.portlet.news.model.NewsFlag"),
			true);

	/**
	 * Converts the soap model instance into a normal model instance.
	 *
	 * @param soapModel the soap model instance to convert
	 * @return the normal model instance
	 */
	public static NewsFlag toModel(NewsFlagSoap soapModel) {
		NewsFlag model = new NewsFlagImpl();

		model.setFlagId(soapModel.getFlagId());
		model.setUserId(soapModel.getUserId());
		model.setCreateDate(soapModel.getCreateDate());
		model.setEntryId(soapModel.getEntryId());
		model.setValue(soapModel.getValue());

		return model;
	}

	/**
	 * Converts the soap model instances into normal model instances.
	 *
	 * @param soapModels the soap model instances to convert
	 * @return the normal model instances
	 */
	public static List<NewsFlag> toModels(NewsFlagSoap[] soapModels) {
		List<NewsFlag> models = new ArrayList<NewsFlag>(soapModels.length);

		for (NewsFlagSoap soapModel : soapModels) {
			models.add(toModel(soapModel));
		}

		return models;
	}

	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.fr.smile.liferay.portlet.news.model.NewsFlag"));

	public NewsFlagModelImpl() {
	}

	public long getPrimaryKey() {
		return _flagId;
	}

	public void setPrimaryKey(long pk) {
		setFlagId(pk);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_flagId);
	}

	public long getFlagId() {
		return _flagId;
	}

	public void setFlagId(long flagId) {
		_flagId = flagId;
	}

	public long getUserId() {
		return _userId;
	}

	public void setUserId(long userId) {
		if (!_setOriginalUserId) {
			_setOriginalUserId = true;

			_originalUserId = _userId;
		}

		_userId = userId;
	}

	public String getUserUuid() throws SystemException {
		return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
	}

	public void setUserUuid(String userUuid) {
		_userUuid = userUuid;
	}

	public long getOriginalUserId() {
		return _originalUserId;
	}

	public Date getCreateDate() {
		return _createDate;
	}

	public void setCreateDate(Date createDate) {
		_createDate = createDate;
	}

	public long getEntryId() {
		return _entryId;
	}

	public void setEntryId(long entryId) {
		if (!_setOriginalEntryId) {
			_setOriginalEntryId = true;

			_originalEntryId = _entryId;
		}

		_entryId = entryId;
	}

	public long getOriginalEntryId() {
		return _originalEntryId;
	}

	public int getValue() {
		return _value;
	}

	public void setValue(int value) {
		if (!_setOriginalValue) {
			_setOriginalValue = true;

			_originalValue = _value;
		}

		_value = value;
	}

	public int getOriginalValue() {
		return _originalValue;
	}

	public NewsFlag toEscapedModel() {
		if (isEscapedModel()) {
			return (NewsFlag)this;
		}
		else {
			return (NewsFlag)Proxy.newProxyInstance(NewsFlag.class.getClassLoader(),
				new Class[] { NewsFlag.class }, new AutoEscapeBeanHandler(this));
		}
	}

	public ExpandoBridge getExpandoBridge() {
		if (_expandoBridge == null) {
			_expandoBridge = ExpandoBridgeFactoryUtil.getExpandoBridge(0,
					NewsFlag.class.getName(), getPrimaryKey());
		}

		return _expandoBridge;
	}

	public void setExpandoBridgeAttributes(ServiceContext serviceContext) {
		getExpandoBridge().setAttributes(serviceContext);
	}

	public Object clone() {
		NewsFlagImpl newsFlagImpl = new NewsFlagImpl();

		newsFlagImpl.setFlagId(getFlagId());

		newsFlagImpl.setUserId(getUserId());

		NewsFlagModelImpl newsFlagModelImpl = newsFlagImpl;

		newsFlagModelImpl._originalUserId = newsFlagModelImpl._userId;

		newsFlagModelImpl._setOriginalUserId = false;
		newsFlagImpl.setCreateDate(getCreateDate());

		newsFlagImpl.setEntryId(getEntryId());

		newsFlagModelImpl._originalEntryId = newsFlagModelImpl._entryId;

		newsFlagModelImpl._setOriginalEntryId = false;
		newsFlagImpl.setValue(getValue());

		newsFlagModelImpl._originalValue = newsFlagModelImpl._value;

		newsFlagModelImpl._setOriginalValue = false;

		return newsFlagImpl;
	}

	public int compareTo(NewsFlag newsFlag) {
		int value = 0;

		if (getUserId() < newsFlag.getUserId()) {
			value = -1;
		}
		else if (getUserId() > newsFlag.getUserId()) {
			value = 1;
		}
		else {
			value = 0;
		}

		if (value != 0) {
			return value;
		}

		value = DateUtil.compareTo(getCreateDate(), newsFlag.getCreateDate());

		if (value != 0) {
			return value;
		}

		return 0;
	}

	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		NewsFlag newsFlag = null;

		try {
			newsFlag = (NewsFlag)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long pk = newsFlag.getPrimaryKey();

		if (getPrimaryKey() == pk) {
			return true;
		}
		else {
			return false;
		}
	}

	public int hashCode() {
		return (int)getPrimaryKey();
	}

	public String toString() {
		StringBundler sb = new StringBundler(11);

		sb.append("{flagId=");
		sb.append(getFlagId());
		sb.append(", userId=");
		sb.append(getUserId());
		sb.append(", createDate=");
		sb.append(getCreateDate());
		sb.append(", entryId=");
		sb.append(getEntryId());
		sb.append(", value=");
		sb.append(getValue());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(19);

		sb.append("<model><model-name>");
		sb.append("fr.smile.liferay.portlet.news.model.NewsFlag");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>flagId</column-name><column-value><![CDATA[");
		sb.append(getFlagId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>userId</column-name><column-value><![CDATA[");
		sb.append(getUserId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>createDate</column-name><column-value><![CDATA[");
		sb.append(getCreateDate());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>entryId</column-name><column-value><![CDATA[");
		sb.append(getEntryId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>value</column-name><column-value><![CDATA[");
		sb.append(getValue());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private long _flagId;
	private long _userId;
	private String _userUuid;
	private long _originalUserId;
	private boolean _setOriginalUserId;
	private Date _createDate;
	private long _entryId;
	private long _originalEntryId;
	private boolean _setOriginalEntryId;
	private int _value;
	private int _originalValue;
	private boolean _setOriginalValue;
	private transient ExpandoBridge _expandoBridge;
}